package com.jiahuiwen.singleton;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 使用单例模式的 饿汉风格读取配置文件信息.
 * 
 * @author jiahui.wen
 * @version 1.0
 */
public class SingletonConfig {
	private String parameterA;
	private String parameterB;
	
	private static SingletonConfig instance = new SingletonConfig();
	
	public static SingletonConfig getInstance() {
		return instance;
	}
 	

	
	public String getParameterA() {
		return parameterA;
	}



	public String getParameterB() {
		return parameterB;
	}



	private SingletonConfig() {
		super();
		readConfig();
	}
	
	private void readConfig() {
		// TODO Auto-generated method stub
		Properties p = new Properties();
		InputStream in = null;
		
		try {
			in = SingletonConfig.class.getResourceAsStream("AppConfig.properties");
			p.load(in);
			parameterA = p.getProperty("paramA");
//			System.out.println("读取的paramA： " + parameterA);
			parameterB = p.getProperty("paramB");
//			System.out.println("读取的paramB： " + parameterB);
		} catch (IOException e) {
			System.out.println("装载配置文件出错");
			e.printStackTrace();
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	
}
